import 'package:flutter/material.dart';
import 'package:flutter_boost/flutter_boost.dart';
import 'package:flutter_module/controller/theme_setting_controller.dart';
import 'package:flutter_module/util/language_res/str_res_keys.dart';
import 'package:flutter_module/util/log_u.dart';
import 'package:get/get.dart';

//参考 from ： https://github.com/lilongweidev/study_language_theme.git
///主题设置页面
class ThemeSettingPage extends StatelessWidget {
  ThemeSettingPage({Key? key}) : super(key: key);

  final controller = Get.find<ThemeSettingsController>();

  // final controller = Get.put(ThemeSettingsController());

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        centerTitle: true,
        title: Text(
          SR.themeSetting.tr,
        ),
      ),
      body: GetBuilder<ThemeSettingsController>(builder: (controller) {
        return Container(
          padding: const EdgeInsets.only(
            top: 10,
          ),
          child: ListView.separated(
              itemBuilder: (context, index) {
                return Container(
                  padding: const EdgeInsets.only(left: 16, right: 16),
                  height: 50,
                  child: InkWell(
                    onTap: () {
                      controller.changeTheme(context, index);
                      //下方的Visibility并未更新
                      LogU.log("changeTheme index = $index");
                      LogU.log(
                          "changeTheme controller.currentThemeIndex = ${controller.currentThemeIndex}");
                      // BoostNavigator.instance.pop(index);
                    },
                    child: Row(
                      children: [
                        Expanded(child: Text(controller.themeList[index])),
                        Visibility(
                            visible: controller.currentThemeIndex == index,
                            child: const Icon(Icons.check_rounded, color: Colors.blue))
                      ],
                    ),
                  ),
                );
              },
              separatorBuilder: (context, index) {
                return const Divider();
              },
              itemCount: controller.themeList.length),
        );
      }),
    );
  }
}
